<form class="layui-form" action="{:url()}" method="post" id="editForm">
    <div class="layui-form-item">
        <label class="layui-form-label">postId</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input field-nick" name="postId" lay-verify="required" placeholder="postId">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input field-username" name="title" lay-verify="required" placeholder="标题">
        </div>
    </div>

    <div class="layui-form-item">
        <label for="image" class="layui-form-label">
            新闻图片地址:
        </label>
        <div class="layui-input-inline">
            <input type="hidden" id="imgSrc" name="imgSrc" lay-verify="imgSrc" class="layui-input" value="">

            <button type="button" class="layui-btn" id="image" name="image">
                上传新闻图片地址
            </button>
        </div>
    </div>

    <div class="layui-form-item" id="myDiv">
        <label for="image" class="layui-form-label" style="color: #b3d271">
            图片预览
        </label>
        <div class="layui-input-inline"></div>
    </div>

    <div class="layui-form-item">
        <label for="image" class="layui-form-label">
            头像地址:
        </label>
        <div class="layui-input-inline">
            <input type="hidden" id="avatar" name="avatar" lay-verify="imgSrc" class="layui-input" value="">

            <button type="button" class="layui-btn" id="avatarImg" name="avatarImg">
                上传头像地址
            </button>
        </div>
    </div>

    <div class="layui-form-item" id="divMy">
        <label for="image" class="layui-form-label" style="color: #b3d271">
            图片预览
        </label>
        <div class="layui-input-inline"></div>
    </div>

    <div class="layui-form-item" >
        <label class="layui-form-label">文章详情</label>
        <div class="layui-input-inline w600"  id="editormd">
            <textarea id="editor-content" class="field-content" name="detail" lay-verify="required"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">作者</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input field-username" name="author" lay-verify="required" placeholder="作者">
        </div>
    </div>

    <div class="pop-bottom-bar">
        <button type="submit" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="formSubmit" hisi-data="{pop: true, refresh: true}">提交保存</button>
        <a href="javascript:parent.layui.layer.closeAll();" class="layui-btn layui-btn-primary ml10">取消</a>
    </div>

</form>
{include file="block/layui" /}
{php}
    /* 加载扩展编辑器 */
    echo editor(['editor-content']);
{/php}
<script>
    layui.use(['form', 'func'], function() {
        var $ = layui.jquery, form = layui.form;
        //layui.func.assign(formData);
    });

    //上传数据
    layui.use(['jquery','upload'], function(){
        var $ = layui.jquery
            ,upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#image', //绑定元素,
            url: './uploadFile/', //上传接口
            done: function(res){
                console.info(res.data);
                //上传完毕回调
                $("#myDiv").append("<img src='"+ res.data +"' style='width:415px;height:250px'>");
                $("#imgSrc").val(res.data);
            },
            error: function(){
                //请求异常回调
            }
        });
        var uploadSecond = upload.render({
            elem: '#avatarImg', //绑定元素,
            url: './uploadAvatarImg/', //上传接口
            done: function(res){
                console.info(res.data);
                //上传完毕回调
                $("#divMy").append("<img src='"+ res.data +"' style='width:100px;height:80px'>");
                $("#avatar").val(res.data);
            },
            error: function(){
                //请求异常回调
            }
        });
    });
</script>
